package com.enlorenz.core.engine.imp.thread.quick;

import com.enlorenz.core.engine.AbstractBuzHandler;
import com.enlorenz.core.engine.imp.thread.ControlThread;

/**
 * 快速抽象的循环控制线程
 * 直接继承此抽象类即可实现线程的循环控制
 * @author Karma
 */
public abstract class AbstractQuickControlThread extends ControlThread{
	{
		buzHandler=new AbstractBuzHandler() {
			@Override
			protected void buzHandleImp() throws Exception {
				AbstractQuickControlThread.this.handle();
			}
			
			protected void onExceptionHappened(Exception e){
				AbstractQuickControlThread.this.onExceptionHappened(e);
			}
			
			protected void onFinallyDo(){
				AbstractQuickControlThread.this.onFinallyDo();
			}
		};
	}
	
	/**
	 * 处理业务
	 * @throws Exception
	 */
	protected abstract void handle() throws Exception;
	
	/**
	 * 发生异常后
	 * @param e
	 */
	protected void onExceptionHappened(Exception e){
		
	}
	
	/**
	 * 一个循环完成始终要做的
	 * @param e
	 */
	protected void onFinallyDo(){
		
	}
}
